<template>
  <div>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="用户账号">
        <el-input
          clearable
          size="small"
          v-model="formInline.account"
          auto-complete="off"
          placeholder="请输入用户账号"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="getData">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      size="small"
      :data="datalist"
      highlight-current-row
      border
      element-loading-text="拼命加载中"
      style="width: 100%;"
    >
      <el-table-column align="center" sortable prop="name" label="用户姓名" min-width="200"></el-table-column>
      <el-table-column align="center" sortable prop="userAccount" label="用户账号" min-width="200"></el-table-column>
      <el-table-column align="center" sortable prop="status" label="账号状态" min-width="200">
        <template slot-scope="scope">{{scope.row.status == 0 ? '正常':'冻结'}}</template>
      </el-table-column>
      <el-table-column align="center" sortable prop="email" label="邮箱" width="250"></el-table-column>
      <el-table-column align="center" label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 0"
            size="mini"
            type="danger"
            @click="del(scope.row,1)"
          >冻结</el-button>
          <el-button v-else size="mini" type="primary" @click="del(scope.row,0)">解冻</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="page-box"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      background
      :current-page="pageparm.currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageparm.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageparm.total"
    ></el-pagination>
  </div>
</template>
<script type="text/ecmascript-6">
import { getUserList, upUserStatus } from "../../api/userMember";
export default {
  data() {
    return {
      formInline: {},
      datalist: [],
      pageparm: {
        currentPage: 0,
        pageSize: 10,
        total: 0
      },
      dialogVisible: false,
      addData: {}
    };
  },
  created() {
    this.getData();
  },
  methods: {
    del(row, status) {
      let param = {};
      param.account = row.userAccount;
      param.status = status;
      upUserStatus(param).then(res => {
        if (res.status == 200) {
          if (res.status == 200) {
            this.$message({
              type: "success",
              message: "操作成功"
            });
          } else {
            this.$message({
              type: "error",
              message: "操作失败"
            });
          }
          this.getData();
        }
      });
    },
    handleCurrentChange(val) {
      this.pageparm.currentPage = val;
      this.getData();
    },
    handleSizeChange(val) {
      this.pageparm.pageSize = val;
      this.getData();
    },
    getData() {
      this.formInline.pageIndex = this.pageparm.currentPage;
      this.formInline.pageSize = this.pageparm.pageSize;
      getUserList(this.formInline).then(res => {
        if (res.status == 200) {
          this.datalist = res.data;
          this.pageparm.total = res.total;
        }
      });
    }
  }
};
</script>